<%@page errorPage="errorPage.jsp" extends="com.epro.standard.frontend.jsp.EproDialog" contentType="text/html; charset=windows-874" import="com.epro.standard.frontend.util.*, com.epro.standard.frontend.system.*, java.util.*"%>
<%!
	private com.epro.standard.frontend.system.ConfirmDB confirmDB ;
	private com.epro.standard.frontend.system.Confirm stdConfirm ;
	private com.epro.standard.frontend.system.ErrorDB errorDB ;
	private com.epro.standard.frontend.system.Error stdError ;
	private com.epro.standard.frontend.system.InfoDB	infoDB ;
	private com.epro.standard.frontend.system.Info	stdInfo ;
	private com.epro.standard.frontend.system.WarningDB warningDB ;
	private com.epro.standard.frontend.system.Warning stdWarning ;

	final public void init()
		throws ServletException {
		confirmDB = new com.epro.standard.frontend.system.ConfirmDB(this.getServletContext()) ;
		errorDB = new com.epro.standard.frontend.system.ErrorDB(this.getServletContext()) ;
		infoDB = new com.epro.standard.frontend.system.InfoDB(this.getServletContext()) ;
		warningDB = new com.epro.standard.frontend.system.WarningDB(this.getServletContext()) ;
	}
%>
<%
	com.epro.standard.frontend.util.TRequest	 thaiRequest = new com.epro.standard.frontend.util.TRequest(request) ;

	String	dType					= thaiRequest.getParameter("type")!=null ? thaiRequest.getParameter("type") : "warning" ;
	String	title						= thaiRequest.getParameter("title")!= null ? thaiRequest.getParameter("title") : "" ;
	String	mHead					= "Notice", dHead = "Detail(s)" ;	// Default for Information Dialog
	String	mBody					= "" ;
	String	dBody					= "" ;
	String	okBtnLabel			= thaiRequest.getParameter("okBtnLabel")!= null ? thaiRequest.getParameter("okBtnLabel") : "OK" ;
	String	cancelBtnLabel	= thaiRequest.getParameter("cancelBtnLabel")!= null ? thaiRequest.getParameter("cancelBtnLabel") : "Cancel" ;
	String	overiddedMessage	= thaiRequest.getParameter("overiddedMessage")!= null ? thaiRequest.getParameter("overiddedMessage") : "" ;


System.out.println("message from dType " + dType) ;
System.out.println("Overide : " + overiddedMessage) ;
//	boolean	noOveriddedMessage = true ;
	if(overiddedMessage.trim().length() > 0) {	// Has request message from programmer.
//		noOveriddedMessage = false ;
		java.util.StringTokenizer tokens = new java.util.StringTokenizer(thaiRequest.getParameter("overiddedMessage").toString(), "|");
		if(tokens.hasMoreTokens())
			mBody = tokens.nextToken() ;
		if(tokens.hasMoreTokens())
			dBody = tokens.nextToken() ;
			
		if(dType.equals("error")) {
			mHead = "Problem" ;
			dHead = "Solution" ;
		}
		if(dType.equals("warning")) {
			mHead = "Warning" ;
			dHead = "Detail(s)" ;
		}
		if(dType.equals("confirm")) {
			mHead = "Confirmation" ;
			dHead = "Detail(s)" ;
		}
	} else {
System.out.println(thaiRequest.getParameter("infoCode")) ;		
		stdInfo = (com.epro.standard.frontend.system.Info) infoDB.getInfoMessage((thaiRequest.getParameter("infoCode") != null ? thaiRequest.getParameter("infoCode") : "")) ;
		mBody = stdInfo.getNotice() ;
		dBody = stdInfo.getInfoDetail() ;

		if(dType.equals("error")) {
			mHead = "Problem" ;
			dHead = "Solution" ;
	
			session.setAttribute("hasError", new String("true")) ;
	
//			String errorCode = "" ;
//			if(! session.getAttribute("hasError").toString().equals("true"))
//				response.sendRedirect("http://www.yahoo.com") ;
System.out.println(thaiRequest.getParameter("errorCode")) ;
			stdError = (com.epro.standard.frontend.system.Error) errorDB.getErrorMessage((thaiRequest.getParameter("errorCode") != null ? thaiRequest.getParameter("errorCode") : "")) ;
			mBody = stdError.getErrorCode() + " " + stdError.getErrorDesc() ;
			dBody = stdError.getSolution() ;
		}
		if(dType.equals("warning")) {
			mHead = "Warning" ;
			dHead = "Detail(s)" ;
System.out.println(thaiRequest.getParameter("warningCode")) ;				
			stdWarning = (com.epro.standard.frontend.system.Warning) warningDB.getWarningMessage((thaiRequest.getParameter("warningCode") != null ? thaiRequest.getParameter("warningCode") : "")) ;
			mBody = stdWarning.getWarningDesc() ;
			dBody = stdWarning.getWarningDetail() ;
		}
		if(dType.equals("confirm")) {
			mHead = "Confirmation" ;
			dHead = "Detail(s)" ;
System.out.println(thaiRequest.getParameter("confirmCode")) ;				
			stdConfirm = (com.epro.standard.frontend.system.Confirm) confirmDB.getConfirmMessage((thaiRequest.getParameter("confirmCode") != null ? thaiRequest.getParameter("confirmCode") : "")) ;
			mBody = stdConfirm.getConfirmDesc() ;
			dBody = stdConfirm.getConfirmDetail() ;
		}
	}	
%>
<HTML>
<HEAD>
<TITLE><%=title%></TITLE>
<%@taglib uri="/WEB-INF/HeadTag.tld" prefix="header"%>
<LINK href="theme/DialogTheme.css" rel="stylesheet" type="text/css">
<META name="GENERATOR" content="IBM WebSphere Studio">
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
	function setFocus() {
		if(document.all.cancelBtn != null)
			document.all.cancelBtn.focus() ;
	}
//-->
</SCRIPT>
</HEAD>
<BODY onLoad="setFocus()">
<DIV CLASS="<%=dType%>DivBound">
	<DIV CLASS="divMessage">
		<TABLE CLASS="messageBound">
		<TR>
			<TD CLASS="messageHead"><%=mHead%> :</TD>
		</TR>
		<TR>
			<TD CLASS="messageBody">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=mBody%></TD>
		</TR>
<%
	if(!(dBody.length() == 0)) {
%>
		<TR>
			<TD CLASS="messageHead"><%=dHead%> :</TD>
		</TR>
		<TR>
			<TD CLASS="messageBody">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=dBody%></TD>
		</TR>
<%
	}	
%>
		</TABLE>
	</DIV>
	<TABLE BORDER="0" STYLE="text-align: right; width: 100%">
		<TR>
			<TD>
			<INPUT TYPE="button" NAME="okBtn" VALUE="<%=okBtnLabel%>" CLASS="dialogBtn" onmouseover="this.className='dialogBtnOnOver'" onmouseout="this.className='dialogBtn'" onclick="returnValue=1;window.close();">
			<%if(dType.equals("confirm")) { %>
			<INPUT TYPE="button" NAME="cancelBtn" VALUE="<%=cancelBtnLabel%>" CLASS="dialogBtn" onmouseover="this.className='dialogBtnOnOver'" onmouseout="this.className='dialogBtn'" onclick="returnValue=2;window.close();">
			<%}%>
			</TD>
			<TD WIDTH="10px"></TD>
		</TR>
	</TABLE>
</DIV>
</BODY>
</HTML>